/**
*      author: Y_Yao
*      created: 2024-11-17 16:52:10
**/

#include<bits/stdc++.h>

#define int LL
using namespace std;
using LL = long long;
const LL LLINF = 1e18;
const int INF = 0x3f3f3f3f;
const int M = 2e6 + 7;
int n,m;
pair<int,int> a[M];
// 5 2
// 1 4
// 3 2

//1 2 3 4 5
//3 0 0 2 0

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> m;
    for(int i = 1;i <= m;i++)
    {
        cin >> a[i].first;
    }
    int sum = 0;
    for(int i = 1;i <= m;i++)
    {
        cin >> a[i].second;
        sum += a[i].second;
    }

    if(sum != n)
    {
        cout << -1 << endl;
        return 0;
    }
    sort(a + 1, a + m + 1);

    int ret = 0;
    int now = n;
    for(int i = m;i >= 1;i--)
    {
        int pos = a[i].first;
        int num = min(a[i].second,now - pos + 1);
        ret += (now - num + 1 - pos + now - pos) * num / 2;
        now -= num;
    }

    if(now == 0)
    {
        cout << ret << endl;
        return 0;
    }

    cout << -1 << endl;

    return 0;
}